//
//  BaseTabbarController.m
//  YUXiu
//
//  Created by 王竞成 on 16/6/22.
//  Copyright © 2016年 Wang. All rights reserved.
//

#import "BaseTabbarController.h"

@interface BaseTabbarController (){
    NSMutableArray *_redDotViews;

}

@end
#define kItemsCount     4 //个数

@implementation BaseTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addRedDot];

    // Do any additional setup after loading the view from its nib.
}

#pragma mark - UI操作
//添加红色小红点
- (void)addRedDot {
    
    _redDotViews = @[].mutableCopy;
    
    CGFloat redViewWidth = 8;
    CGFloat itemWidth = kScreenWidth / kItemsCount;
    CGFloat itemCenter = itemWidth / 2.0;
    
    for (int i = 0; i < kItemsCount; i++) {
        UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(itemCenter + 5 + itemWidth * i, kScreenHeight - 40, redViewWidth, redViewWidth)];
        redView.backgroundColor = [UIColor redColor];
        redView.layer.cornerRadius = redViewWidth * 0.5;
        redView.hidden = YES;
        [_redDotViews addObject:redView];
        [self.view addSubview:redView];
    }
    
}

#pragma mark -
#pragma mark - 事件操作
- (void)redDotIsShow:(BOOL)show Index:(NSInteger)index {
    UIView *redView = _redDotViews[index];
    redView.hidden = !show;
}

- (void)setBadgeValue:(NSInteger)badgeValue Index:(NSInteger)index {
    
    if (badgeValue == 0) {
        [[self.tabBar.items objectAtIndex:index] setBadgeValue:nil];
    }else {
        [[self.tabBar.items objectAtIndex:index] setBadgeValue:[NSString stringWithFormat:@"%ld",(long)badgeValue]];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
